
package view.utils;

import java.io.File;
import javax.swing.filechooser.FileFilter;

/**
 *
 * @author Marcos Garcia Ortega <a href="mailto:thiamath@gmail.com">&lt;thiamath@gmail.com&gt;</a>
 */
public class ExtensionFilter extends FileFilter{

	private String description;
	private String[] extensions;

	public ExtensionFilter(String description, String... extensions) {
		this.description = description;
		this.extensions = extensions;
	}

	@Override
	public boolean accept(File f) {
		boolean ret = false;
		String fileName = f.getName();
		
		if(f != null && fileName != null && fileName.equals("")){
			fileName = fileName.substring(fileName.lastIndexOf('.'));
			for (String ext : extensions) {
				if(fileName.equalsIgnoreCase(ext)){
					ret = true;
					break;
				}
			}
		}

		return ret;
	}

	@Override
	public String getDescription() {
		return description;
	}

}
